package com.springapp.service.impl;

import com.springapp.model.Desk;
import com.springapp.repository.TableRepository;
import com.springapp.service.TableService;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kataeva.nat
 */
@Service
@Transactional
public class TableServiceImpl implements TableService {

    @Autowired
    private TableRepository tableRepository;

    @Override
    public Desk getById(Integer id) {
        return tableRepository.findOne(id);
    }

    @Override
    public List<Desk> getAll() {
        return (ArrayList<Desk>) tableRepository.findAll();
    }

    @Override
    public void create(Desk desk) {
        tableRepository.save(desk);
    }

    @Override
    public Desk update(Desk desk) {
        return tableRepository.save(desk);
    }

    @Override
    public void delete(Integer id) {
        tableRepository.delete(id);
    }
}
